<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.UserDAO"%>
<%@page import="db.User"%>

<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	UserDAO userDao = (UserDAO)ctx.getBean("UserDAO");
	
	String account = request.getParameter("account");
	String password = request.getParameter("password");
	String rand = (String)session.getAttribute("rand");
	
	
		if(account != null && !"".equals(account.trim())){
			if(password != null && !"".equals(password.trim())){
				List list = userDao.findByAccount(account);
				if(list != null && list.size() > 0){
					for(int i=0;i < list.size();i++){
						User user = (User)list.get(i);
						if(password.equals(user.getPassword())){
							session.setAttribute("id",user.getId());
							pageContext.forward("/vm/erp_tpl/erp_index.html.html");
							return;
						}else{
							request.setAttribute("error",2);
							pageContext.forward("/vm/index.vm");
							return;
						}
					}
				}else{
					request.setAttribute("error",1);
					pageContext.forward("/vm/index.vm");
					return;
				}
			}else{
				request.setAttribute("error",2);
				pageContext.forward("/vm/index.vm");
				return;
			}
		}else{
			request.setAttribute("error",1);
			pageContext.forward("/vm/index.vm");
			return;
		}
	
%>
